import { Camera, Canvas } from 'cc';
import { LoggerComponent } from '../components';
import { ccclass, cccomponent, disallowMultiple, modifier, requireComponent } from '../decorators';
import { Environment } from '../declarations';
import { Background, BigLoading, Dummy, Hint, Top, TouchMask, Screen, Window, Popup } from '../view';
import { app } from './Application';

/**
 * - 作者: DoooReyn
 * - 日期: 2023.10.30
 * - 名称: View
 * - 描述: 视图组件
 */
@ccclass()
@disallowMultiple(true)
@requireComponent(Canvas)
@modifier('View')
export class View extends LoggerComponent {
    @cccomponent(Canvas, '.')
    canvas!: Canvas;

    @cccomponent(Camera, 'Camera')
    camera!: Camera;

    @cccomponent(Background, 'Background')
    background!: Background;

    @cccomponent(Screen, 'Screen')
    screen!: Screen;

    @cccomponent(Window, 'Window')
    window!: Window;

    @cccomponent(Popup, 'Popup')
    popup!: Popup;

    @cccomponent(BigLoading, 'BigLoading')
    bigLoading!: BigLoading;

    @cccomponent(Dummy, 'Dummy')
    dummy!: Dummy;

    @cccomponent(Hint, 'Hint')
    hint!: Hint;

    @cccomponent(Top, 'Top')
    top!: Top;

    protected async launch(env: Environment) {
        // 初始化应用
        await app.init(this, env);

        // 启动应用
        await app.start();
    }

    /** 初始化视图 */
    public async init() {
        await app.view.top.init();
        await app.view.hint.init();
        await app.view.bigLoading.init();
        await app.view.dummy.init();
        await app.view.popup.init();
        await app.view.window.init();
        await app.view.screen.init();
        await app.view.background.init();
    }

    /** 进入视图 */
    public async restore() {
        await app.view.top.enter();
        await app.view.hint.enter();
        await app.view.bigLoading.enter();
        await app.view.dummy.enter();
        await app.view.popup.enter();
        await app.view.window.enter();
        await app.view.screen.enter();
        await app.view.background.enter();
    }

    /** 退出视图 */
    public async clear() {
        await app.view.top.exit();
        await app.view.hint.exit();
        await app.view.bigLoading.exit();
        await app.view.dummy.exit();
        await app.view.popup.exit();
        await app.view.window.exit();
        await app.view.screen.exit();
        await app.view.background.exit();
    }
}
